#if (FEATURE_MODE == 0)
/**
 @file ctc_sync_ether_cli.c

 @date 2012-10-18

 @version v2.0

 This file defines functions for SyncE cli module

*/

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctc_asw_common.h"
#include "ctcs_api.h"

CTC_CLI(ctc_cli_asw_sync_ether_set_cfg,
        ctc_cli_asw_sync_ether_set_cfg_cmd,
        "sync-ether clock CLOCK_ID recovered-port LPORT divider DIVIDER {output (enable | disable) |}",
        CTC_CLI_SYNC_ETHER_M_STR,
        "SyncE clock",
        "SyncE clock ID",
        "The port used for recover clock",
        "Local port ID",
        "Clock divider",
        "Divider value",
        "Clock output enable or disable",
        "Clock output enable",
        "Clock output disable")
{
    int32 ret = 0;
    uint8 sync_ether_clock = 0;
    uint8 index = 0;
    ctc_sync_ether_cfg_t sync_ether_cfg;

    sal_memset(&sync_ether_cfg, 0, sizeof(sync_ether_cfg));

    CTC_CLI_GET_UINT8_RANGE("clock-id", sync_ether_clock, argv[0], 0, CTC_MAX_UINT8_VALUE);
    CTC_CLI_GET_UINT16_RANGE("lport", sync_ether_cfg.recovered_clock_lport, argv[1], 0, CTC_MAX_UINT16_VALUE);
    CTC_CLI_GET_UINT16_RANGE("divider", sync_ether_cfg.divider, argv[2], 0, CTC_MAX_UINT16_VALUE);

    index = CTC_CLI_GET_ARGC_INDEX("output");
    if (index != 0xFF)
    {
        if (CLI_CLI_STR_EQUAL("enable", index + 1))
        {
            sync_ether_cfg.clock_output_en = 1;
        }
    }

    ret = ctcs_sync_ether_set_cfg(g_api_lchip, sync_ether_clock, &sync_ether_cfg);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_sync_ether_show_cfg,
        ctc_cli_asw_sync_ether_show_cfg_cmd,
        "show sync-ether clock CLOCK_ID (recovered-port LPORT|)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_SYNC_ETHER_M_STR,
        "SyncE clock",
        "SyncE clock ID",
        "The port used for recover clock",
        "Local port ID")
{
    int32 ret = 0;
    uint8 sync_ether_clock = 0;
    uint8 index = 0;
    char* str = NULL;
    ctc_sync_ether_cfg_t sync_ether_cfg;

    sal_memset(&sync_ether_cfg, 0, sizeof(sync_ether_cfg));

    CTC_CLI_GET_UINT8_RANGE("clock-id", sync_ether_clock, argv[0], 0, CTC_MAX_UINT8_VALUE)

    index = CTC_CLI_GET_ARGC_INDEX("recovered-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("lport", sync_ether_cfg.recovered_clock_lport, argv[index+1], 0, CTC_MAX_UINT16_VALUE);
    }

    ret = ctcs_sync_ether_get_cfg(g_api_lchip, sync_ether_clock, &sync_ether_cfg);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("==============================\n");
    ctc_cli_out("sync-ether clock   :%d\n", sync_ether_clock);
    ctc_cli_out("recovered-port     :%d\n", sync_ether_cfg.recovered_clock_lport);
    ctc_cli_out("divider            :%d\n", sync_ether_cfg.divider);
    str = sync_ether_cfg.clock_output_en ? "enable" : "disable";
    ctc_cli_out("output             :%s\n", str);
    ctc_cli_out("==============================\n");

    return CLI_SUCCESS;
}

/**
 @brief  Initialize sdk SyncE module CLIs
*/
int32
ctc_asw_sync_ether_cli_init(uint8 cli_tree_mode)
{
    install_element(cli_tree_mode, &ctc_cli_asw_sync_ether_set_cfg_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_sync_ether_show_cfg_cmd);

    return CLI_SUCCESS;
}
#endif

